﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using YWTSSys.BLL;
using YWTSSys.Model;
using System.Text;

namespace YWTSSys.Web.MachineSys
{
    public partial class Default : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "Default";
            }
        }

       
        #region 
        /// <summary>
        /// 获取当前用户对应的菜单信息
        /// </summary>
        /// <returns></returns>
        protected string GetMenu()
        {
            /*
                    <div class="accordionHeader">
                        <h2><span>Folder</span>系统管理</h2>
                    </div>					
                    <div class="accordionContent">
                        <ul class="tree">
                            <li><a href="SysBasic/OMeunList.aspx" target="navTab" rel="OMenuList">系统页面管理</a></li>	
                            <li><a href="SysBasic/ORoleList.aspx" target="navTab" rel="ORoleList">角色管理</a></li>							
                        </ul>
                    </div>
             */
            StringBuilder sb = new StringBuilder();
            List<OMenuInfo> allmenudt =User.IsSuperAdmin?OMenuController.GetAllOMenu2(): ORoleController.GetRoleMenu(User.RoleId);
            allmenudt = allmenudt.FindAll(e => e.IsUsed);
            List<OMenuInfo> alltopmenu = allmenudt.FindAll(e => e.ParMenuId == 0 && e.IsUsed).OrderBy(e => e.DispayIndex).ToList();
            foreach (OMenuInfo topmenuitem in alltopmenu)
            {
                sb.AppendLine("<div class=\"accordionHeader\">");
                sb.AppendFormat("<h2><span>Folder</span>{0}</h2>",topmenuitem.MenuName);
                sb.AppendLine("</div>");

                sb.AppendLine("<div class=\"accordionContent\">");
                sb.AppendLine("<ul class=\"tree treeFolder\">");
                List<OMenuInfo> allsubmenu =allmenudt.FindAll(e => e.ParMenuId == topmenuitem.MenuId).OrderBy(e => e.DispayIndex).ToList() ;
                foreach (OMenuInfo submenuitem in allsubmenu)
                {
                    sb.AppendFormat(" <li><a href=\"{0}\" target=\"{1}\" rel=\"{2}\" fresh=\"{3}\">{4}</a>{5}</li>",submenuitem.DWZHref,submenuitem.DWZTarget,submenuitem.DWZRel,submenuitem.DWZFlesh.ToString().ToLower(),submenuitem.MenuName,Get3Menu(submenuitem.MenuId));
                    
                }
                sb.AppendLine("</ul></div>");
            }

            return sb.ToString();
        }

        protected string Get3Menu(int ParId)
        {
            List<OMenuInfo> allmenudt = User.IsSuperAdmin ? OMenuController.GetAllOMenu2() : ORoleController.GetRoleMenu(User.RoleId);
            allmenudt = allmenudt.FindAll(e => e.IsUsed);
            List<OMenuInfo> allsubmenu =allmenudt.FindAll(e => e.ParMenuId == ParId).OrderBy(e => e.DispayIndex).ToList() ;
            if (allsubmenu.Count <= 0)
                return "";
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<ul>");
            foreach (OMenuInfo submenuitem in allsubmenu)
            {
                sb.AppendFormat(" <li><a href=\"{0}\" target=\"{1}\" rel=\"{2}\" fresh=\"{3}\">{4}</a></li>", submenuitem.DWZHref, submenuitem.DWZTarget, submenuitem.DWZRel, submenuitem.DWZFlesh.ToString().ToLower(), submenuitem.MenuName);
            }
            sb.AppendLine("</ul>");
            return sb.ToString();
        }

        protected string GetHMenu()
        {
            /*
             <ul id="coolMenu">
		
			        <li><a href="#">系统管理</a></li>
			        <li><a href="#">公共查询</a></li>
			        <li>
				        <a href="#">整机管理系统</a>
				        <ul class="noJS">
					        <li><a href="#">作业日报表管理</a></li>
					        <li><a href="#">作业项目定义</a></li>
					        <li><a href="#">机器库存一浪表</a></li>
				        </ul>
			        </li>
			        <li><a href="#">Tyrio</a></li>
			        <li><a href="#">Quicumque</a></li>

		        </ul>
             */
            StringBuilder sb = new StringBuilder();
            List<OMenuInfo> allmenudt = User.IsSuperAdmin ? OMenuController.GetAllOMenu2() : ORoleController.GetRoleMenu(User.RoleId);
            allmenudt = allmenudt.FindAll(e => e.IsUsed);
            List<OMenuInfo> alltopmenu = allmenudt.FindAll(e => e.ParMenuId == 0 && e.IsUsed).OrderBy(e => e.DispayIndex).ToList();
            foreach (OMenuInfo topmenuitem in alltopmenu)
            {
                sb.AppendLine("<li>");
                sb.AppendFormat("<a href=\"#\">{0}</a>", topmenuitem.MenuName);               
                sb.AppendLine("<ul class=\"noJS\">");
                List<OMenuInfo> allsubmenu = allmenudt.FindAll(e => e.ParMenuId == topmenuitem.MenuId).OrderBy(e => e.DispayIndex).ToList();
                foreach (OMenuInfo submenuitem in allsubmenu)
                {
                    sb.AppendFormat(" <li><a href=\"{0}\" target=\"{1}\" rel=\"{2}\" fresh=\"{3}\">{4}</a></li>", submenuitem.DWZHref, submenuitem.DWZTarget, submenuitem.DWZRel, submenuitem.DWZFlesh.ToString().ToLower(), submenuitem.MenuName);
                }
                sb.AppendLine("</ul></li>");
            }

            return sb.ToString();
        }
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (OUserController.CurrentUser.UserName.ToLower() == OUserController.CurrentUser.PassWord.ToLower())
            {
                //需更换初始密码
                Response.Redirect(this.ResolveUrl("~/MachineSys/UpdateInitPwd.aspx"));
            }
            OUserController.UpdateLastLogin(base.User.UserId, Request.UserHostAddress);

           // SyncSAPController.SyncUClaimDemage();
        }

       
    }
}